<?
if (!defined('MODULE_FILE')){
	die ("cant access file directly!");
}

$mid 	= ( ( true == isset( $_GET['mid'] ) && true == valStr( $_GET['mid'] ) ) ? $_GET['mid'] : NULL );
$smid 	= ( ( true == isset( $_GET['smid'] ) && true == valStr( $_GET['smid'] ) ) ? $_GET['smid'] : NULL );

autoLoader();

$objBaseChargeTypes 	= new BaseChargeTypes();
$objChargeTypes 	= new ChargeTypes();
$objChargeCatagories 	= new ChargeCatagories();
?>
<html>
<head>
<?php require_once 'commonJS.php'; ?>
</head>
<body>

	<div style="margin-left:20px; margin-top: 10px;">
		<p>
			<a class="btn btn-outline btn-primary btn-xs" id="active" href="modules.php?file=charge_types&mid=<? echo $mid;?>&smid=<? echo $smid;?>" >Create New Charge Type</a>&nbsp;
			<a class="btn btn-outline btn-primary btn-xs" id="active" href="modules.php?file=view_charge_types&type=view&mid=<? echo $mid;?>&smid=<? echo $smid;?>" >View All Charge Type</a>
		</p>
	</div>
<div class="col-lg-8">
<div class="panel panel-primary">
<div class="panel-heading"><i class="fa fa-bell fa-fw"></i> Charge Types</div>
<div class="panel-body">
	<form METHOD="POST" action="modules.php?file=insert_charge_types&type=insert&mid=<? echo $mid; ?>&smid=<? echo $smid; ?>" id="formSubmit" name="formSubmit" >
		<?php
		$intChargeTypeId = NULL;
		$intChargeCatagoryId = NULL;
		$strName 			  = NULL;
		$strDescription 	  = NULL;
		$intCbArea            = NULL;
        $intOutOfCa           = NULL;
	    $intBelowPriorityLine = NULL;
		
		if( true == isset( $_GET['charge_type_id'] ) && true == valStr( $_GET['charge_type_id'] ) ) {
			$intChargeTypeId = $_GET['charge_type_id'];
			
			$objBaseChargeTypes = $objChargeTypes->fetchChargeTypesById( $_GET['charge_type_id'] );
			
			if( true == valObj( $objBaseChargeTypes, 'BaseChargeTypes' ) ) {
				$intChargeCatagoryId 	= $objBaseChargeTypes->getChargeCatagoryId();
				$strName 				= $objBaseChargeTypes->getName();
				$strDescription 		= $objBaseChargeTypes->getDescription();
				$intCbArea 		        = $objBaseChargeTypes->getCbArea();
				$intOutOfCa 		    = $objBaseChargeTypes->getOutOfCa();
				$intBelowPriorityLine 	= $objBaseChargeTypes->getBelowPriorityLine();
			}
		} else if( true == valObj( $objBaseChargeTypes, 'BaseChargeTypes' ) ) {
			$intChargeTypeId = $objBaseChargeTypes->fetchNextId();
		}
		?> 	
		<table width="80%" cellspacing="0" cellpadding="3">

		<tr><td height="10" colspan="2"><input id="charge_type_id" Name="charge_type_id" type="hidden"  style="width:100px;"  value="<?php echo $intChargeTypeId;?>"></td></tr>
             <tr valign="top">
				<td  width="220">Charge Category ID</td> 
				<td>
		        <select class="validate[required]" name="charge_catagory_id" id="charge_catagory_id" style="width:202px;">
				<option value=''>-Select-</option>
				<?php
					$arrChargeCatagories = $objChargeCatagories->fetchAllChargeCatagories();
					
					if( true == valStr( $arrChargeCatagories ) ) {
						foreach( $arrChargeCatagories as $objChargeCat ) {
							echo '<option' . ( ( $intChargeCatagoryId == $objChargeCat->getId() ) ? ' selected' : '' ) . ' value=' . $objChargeCat->getId() . '>' . $objChargeCat->getName() . '</option>';
						}
					}
					?>
				</select>
				</td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
					
			<tr valign="top">
				<td  width="220">Name</td>
				<td><input id="name" Name="name" type="text" class="validate[required]" value="<?php echo $strName; ?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			  <tr valign="top">
				<td  width="220">Description</td>
				<td><textarea name="description" rows="5" cols="40"><?php echo $strDescription; ?></textarea></td>
			</tr>
			<tr><td colspan="2" height="10px"></td></tr>
			<tr valign="top">
				<td  width="220">CA</td>
				<td><input id="cacharge" Name="cacharge" type="text" class="validate[required]" value="<?php echo $intCbArea; ?>" style="width:202px;"></td>
			</tr>
			<tr><td colspan="2" height="10px"></td></tr>
			<tr valign="top">
				<td  width="220">Out Of CA</td>
				<td><input id="outcacharge" Name="outcacharge" type="text" class="validate[required]" value="<?php echo $intOutOfCa; ?>" style="width:202px;"></td>
			</tr>
			<tr><td colspan="2" height="10px"></td></tr>
			<tr valign="top">
				<td  width="220">Below PL</td>
				<td><input id="bplcharge" Name="bplcharge" type="text" class="validate[required]" value="<?php echo $intBelowPriorityLine; ?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td class="mandatory" width="220">&nbsp;</td>
				<td>
				<?php
						if( true == isset( $_GET['charge_type_id'] ) && true == valStr( $_GET['charge_type_id'] ) ) {
							echo "<input type=hidden name=operation value=update>";
							echo "<input type=submit value=UPDATE id=Submit name=Submit>";
						} else {
							echo "<input type=hidden name=operation value=insert>";
							echo "<input type=submit value=SUBMIT id=Submit name=Submit>";
						}
					?>
				</td> 				
			</tr>
		</table>
</div>
</div>
</div>	
</form>
</body>
</html>